﻿namespace Service.Base
{
    public class ResultHelperService : IResultHelperService
    {
        private IRedisService _Redis;

        #region Success

        public RM_ApiResult BuildActionSuccess(object data)
        {
            var result = new RM_ApiResult() { IsAction = true, Data = data, Success = true, Status = Enum_SysAttributeType.Http.Success };

            result.Msg = _Redis.GetI18nValue(result.Status);

            return result;
        }

        public RM_ApiResult BuildActionSuccess()
        {
            var result = new RM_ApiResult() { IsAction = true, Data = null, Success = true, Status = Enum_SysAttributeType.Http.Success };

            result.Msg = _Redis.GetI18nValue(result.Status);

            return result;
        }

        public RM_ApiResult BuildSuccess(object data)
        {
            var result = new RM_ApiResult() { IsAction = false, Data = data, Success = true, Status = Enum_SysAttributeType.Http.Success };

            result.Msg = _Redis.GetI18nValue(result.Status);

            return result;
        }

        public RM_ApiResult BuildSuccess()
        {
            return BuildSuccess(null);
        }

        #endregion Success

        #region Error

        public RM_ApiResult BuildError(string errorCode, object data)
        {
            var result = new RM_ApiResult() { IsAction = false, Data = data, Success = false, Status = errorCode };

            result.Msg = _Redis.GetI18nValue(result.Status);

            return result;
        }

        public RM_ApiResult BuildError(string errorCode)
        {
            return BuildError(errorCode, null);
        }

        public RM_ApiResult BuildError()
        {
            return BuildError(Enum_SysAttributeType.Misc.RequestTooMany, null);
        }

        public RM_ApiResult BuildActionError(string errorCode)
        {
            return BuildActionError(errorCode, null);
        }

        public RM_ApiResult BuildActionError(string errorCode, object data)
        {
            var result = new RM_ApiResult() { IsAction = true, Data = data, Success = false, Status = errorCode };

            result.Msg = _Redis.GetI18nValue(result.Status);

            return result;
        }

        public RM_ApiResult BuildActionError()
        {
            return BuildActionError(Enum_SysAttributeType.Http.Error, null);
        }

        #endregion Error

        public void SetRedisService(IRedisService redis)
        {
            _Redis = redis;
        }
    }
}